package com.demo.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.common.ResultData;
import com.demo.config.datasource.annotation.DS;
import com.demo.config.datasource.annotation.DynamicDSEnum;
import com.demo.entity.UserEntity;
import com.demo.mapper.UserMapper;
import com.demo.service.UserService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wangfengchen
 * @since 2025-08-21
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> implements UserService {

  @DS(DynamicDSEnum.SLAVE)
  @Override
  public ResultData add2() {
    UserEntity userEntity = new UserEntity();
    userEntity.setId(IdUtil.getSnowflakeNextId());
    userEntity.setUsername(IdUtil.getSnowflakeNextIdStr());
    userEntity.setAge(18);
    userEntity.setCreateTime(new Date());
//    DataSourceContextHolder.clearDataSourceKey();
//    DataSourceContextHolder.setDataSourceKey(DynamicDSEnum.SLAVE.getDesc());
    super.save(userEntity);
//    super.save(testEntity);
//    DataSourceContextHolder.clearDataSourceKey();
//    int i = 1 / 0;
    return ResultData.success();
  }


}
